//
//  IMAudioMessage.m
//  MLIM
//
//  Created by molon on 15/6/28.
//  Copyright (c) 2015年 molon. All rights reserved.
//

#import "IMAudioMessage.h"
#import "IMCommon.h"

@implementation IMAudioMessage

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.audioURL = [coder decodeObjectForKey:SELSTR(audioURL)];
        self.duration = [[coder decodeObjectForKey:SELSTR(duration)] doubleValue];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [super encodeWithCoder:aCoder];
    
    [aCoder encodeObject:self.audioURL forKey:SELSTR(audioURL)];
    [aCoder encodeObject:@(self.duration) forKey:SELSTR(duration)];
}

- (id)simpleDescription
{
    static NSString *audioSign = @"[语音]";
    
    if (self.unheared) {
        NSAttributedString *attrStr = [[NSAttributedString alloc]initWithString:audioSign attributes:@{NSForegroundColorAttributeName:IM_RED_TEXT_COLOR}];
        
        return attrStr;
    }else{
        return audioSign;
    }
}

- (BOOL)unheared
{
    return [IMCM isUnhearedForAudioMessageId:self.messageId];
}

- (void)setHeared
{
    [IMCM signHearedForAudioMessageId:self.messageId];
}

@end
